<?php
/**
 * Created by PhpStorm.
 * User: mt
 * Date: 2018/10/13
 * Time: 16:24
 */

namespace App\Admin\Extensions\Tools;
use Encore\Admin\Admin;
use Encore\Admin\Grid\Tools\AbstractTool;


class ImportExcel extends AbstractTool
{
    protected function script()
    {
        return <<<EOT
$('#import-submit').on('click', function () {
     var formData = new FormData();
     formData.append("import_file",document.getElementById("import-file").files[0]);
            $.ajax({
                type: "POST",
                url: "/api/import",
                data: formData,
                async: true,
                processData: false,
                contentType: false,
                success:function(res){
                 if(res.error){
                   alert(res.error)
                }
                }
            });
         
    toastr.warning('正在上传,请稍后...', '');
});
EOT;
    }

    public function render()
    {
        Admin::script($this->script());

        return view('admin.tools.import_excel');


    }
}